using System.Collections;
using System.Collections.Generic;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;
using QFramework;
using UnityEngine;

namespace HareGame
{
    [TaskCategory("引导")]
    public class ShowDialog : Action
    {
        [Header("对话框多语言Key")]
        public string[] Key;

        private int _completeCount;
        private UIDialog _ui;

        public override void OnStart()
        {
            base.OnStart();
            _completeCount = 0;
            _ui = GameEntry.UI.OpenUI<UIDialog>(UILevel.CanvasPanel, new UIDialogData() { Key = Key[0] });
        }

        public override TaskStatus OnUpdate()
        {
            if (_ui.CanNext)
            {
                _completeCount++;
                if (_completeCount == Key.Length)
                {
                    GameEntry.UI.CloseUI(_ui);
                    return TaskStatus.Success;
                }
                _ui.ShowMsg(Key[_completeCount]);
            }
            return TaskStatus.Running;
        }
    }
}